package com.ywkj.ktyunxiao.utils;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
 * 统一JSON数据返回类
 * @author Administrator
 * @date 2017-12-21 15:22
 */
@JsonInclude(JsonInclude.Include.NON_NULL)
public class JsonResult<T> {

    public static final String SUCCESS = "success";
    public static final String ERROR = "error";
    public static final String UNLOGIN = "unlogin";
    public static final String TOKEN_EXPIRE = "token_expire";
    public static final String TOKEN_ERROR = "token_error";
    public static final String WARNING = "warning";

    private String state;
    private T data;
    private String message;

    public JsonResult() {
    }

    public JsonResult(String state) {
        this.state = state;
    }

    public JsonResult(String state, T data) {
        this.state = state;
        this.data = data;
    }

    public JsonResult(String state, String message) {
        if(state.equals(ERROR) || state.equals(WARNING)){
            this.message = message;
        }else{
            this.data = (T) message;
        }
        this.state = state;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
